from flask import Flask
from flask_socketio import SocketIO

from app.services.FlaskServer import MyCustomNamespace


def create_app(debug=False):
    app = Flask(__name__, template_folder="templates")
    app.debug = debug
    socketio = SocketIO(app, engineio_logger=True, logger=True, cors_allowed_origins='http://127.0.0.1:8000')
    # 注意:Flask-Socketio用on_namespace;Python-Socketio用register_namespace
    socketio.on_namespace(MyCustomNamespace('/channel_A'))
    app.config['SECRET_KEY'] = 'secret!'
    from app.routes import main as chat_routes
    app.register_blueprint(chat_routes)
    return app
